home *** CD-ROM | disk | FTP | other *** search
/ PC Administrator / spravce.iso / TaskModule / src / CTaskModule Test.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-10  |  1.7 KB  |  59 lines

  1. // CTaskModule Test.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. char * GetFileDirectory(const char *pProgramPath,char *pCurrentDirectory);
  7. void SetAppDirectoryAsCurrent(void);
  8.  
  9. int APIENTRY WinMain(HINSTANCE hInstance,
  10.                      HINSTANCE hPrevInstance,
  11.                      LPSTR     lpCmdLine,
  12.                      int       nCmdShow)
  13. {
  14.      // get the directory of the program
  15.     SetAppDirectoryAsCurrent();
  16.     // TODO: Place code here.
  17.     CTaskModule *tmApp = new CTaskModule;
  18.     tmApp->Init();
  19.  
  20.     MSG msg = {NULL};
  21.     HACCEL hAccelTable = NULL;
  22.  
  23.     // Main message loop:
  24.     while (GetMessage(&msg, NULL, 0, 0)) 
  25.     {
  26.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
  27.         {
  28.             TranslateMessage(&msg);
  29.             DispatchMessage(&msg);
  30.         }
  31.     }
  32.  
  33.     delete tmApp;
  34.     return msg.wParam;
  35. }
  36.  
  37. char * GetFileDirectory(const char *pProgramPath,char *pCurrentDirectory)
  38. {// begin GetFileDirectory
  39.     for(int i = lstrlen(pProgramPath)-1;i >= 0;i--)
  40.         if(pProgramPath[i] == '\\')
  41.         {// begin copy directory name into buffer
  42.             lstrcpyn(pCurrentDirectory,pProgramPath,i+1);
  43.             break;
  44.         }// end copy directory name into buffer
  45.     return pCurrentDirectory;
  46. }// end GetFileDirectory
  47.  
  48. void SetAppDirectoryAsCurrent(void)
  49. {// begin SetAppDirectoryAsCurrent
  50.     // get the directory of the program
  51.     char pCurrentDirectory[MAX_PATH] = {NULL};
  52.     char pProgramPath[MAX_PATH] = {NULL};
  53.     GetModuleFileName(GetModuleHandle(NULL),pProgramPath,MAX_PATH-1);
  54.     // turn into a directory
  55.     GetFileDirectory(pProgramPath,pCurrentDirectory);
  56.     // set the current directory to the one the program is running from
  57.     SetCurrentDirectory(pCurrentDirectory);
  58. }// end SetAppDirectoryAsCurrent
  59.